package com.aijk.ehm.api;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.exception.ErrorCodeException;
import com.aijk.commons.mijo.utils.PojoUtil;
import com.aijk.ehm.model.BasUser;
import com.aijk.ehm.model.EhmCompany;
import com.aijk.ehm.model.dto.BasUserDto;
import com.aijk.ehm.model.qo.BasUserQo;
import com.aijk.ehm.model.vo.BasUserVo;
import com.aijk.ehm.model.vo.EhmCompanyVo;
import com.aijk.ehm.service.BasUserService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("basUserApiImpl")
@Transactional
public class BasUserApiImpl implements BasUserApi {
    private static Logger logger = LoggerFactory.getLogger(BasUserApiImpl.class);

    @Autowired
    private BasUserService service;

    @Override
    public Long save(BasUserDto bean) throws ErrorCodeException {
        service.save(bean);
        return bean.getId();
    }

    @Override
    public void update(BasUserDto bean) throws ErrorCodeException {
        service.update(bean);
    }

    @Override
    public BasUserVo findOne(Long id) throws ErrorCodeException {
        return PojoUtil.convert(service.findOne(id) , BasUserVo.class);
    }

    @Override
    public List<BasUserVo> list(BasUserQo qo) {
        return PojoUtil.convert(service.find(qo) , BasUserVo.class);
    }

    @Override
    public void deleteById(Long id) throws ErrorCodeException {
        service.delete(id);
    }

    @Override
    public int count(BasUserQo qo) {
        return service.count(qo);
    }

    @Override
    public PageInfo<BasUserVo> page(BasUserQo qo) {
        PagingRequest pagingRequest = new PagingRequest(qo.getPageNo().intValue(), qo.getPageSize().intValue());
        PageInfo<BasUser> pagelist = service.page(pagingRequest,qo);
        PageInfo<BasUserVo> pagelistvo = PojoUtil.convert(pagelist, PageInfo.class);
        List<BasUser> list = pagelist.getList();
        List<BasUserVo> listvo = PojoUtil.convert(list, BasUserVo.class);
        pagelistvo.setList(listvo);
        return pagelistvo;
    }
}